'use strict'

const { logger } = require('ee-core/log')
const fs = require('node:fs')

/**
 * 文件系统
 */
class FsController
{
    /**
     * 查看所给路径是否是有效的目录系统
     */
    async checkIsDir (args, event) {
        const ret = {
            Success: 'Success',
            NoDir: 'NoDir',
            NoExist: 'NoExist'
        }
        try {
            const states = fs.statSync( args.path )
            if ( !states.isDirectory() ) {
                return ret.NoDir
            }

            return ret.Success
        } catch (error) {
            logger.error(FsController.toString(), error)
            return ret.NoExist
        }
    }
}

FsController.toString = () => '[class FsController]'
module.exports = FsController